//
// Created by 36845 on 25-6-11.
//

#include "Flight.h"
Flight::Flight(string num, string dep, string dest, string time,int te, int le, int tb, int lb, double ep, double bp)
:flightNum(num), departure(dep), destination(dest), departTime(time),totalEconomy(max(0, te)), leftEconomy(max(0, le)),totalBusiness(max(0, tb)), leftBusiness(max(0, lb)),economyPrice(max(0.0, ep)), businessPrice(max(0.0, bp)) {
    if (flightNum.empty()) {
        throw invalid_argument("航班号不能为空！");
    }
    if (departure.empty()||destination.empty()) {
        throw invalid_argument("起降地不能为空！");
    }
}
void Flight::updateSeat(SeatType seatType, int delta) {
    int& targetSeat = (seatType == SeatType::ECONOMY) ? leftEconomy : leftBusiness;
    targetSeat = max(0, targetSeat + delta);
    if (seatType == SeatType::ECONOMY && targetSeat > totalEconomy) {
        targetSeat = totalEconomy;
        cerr << "警告：经济舱剩余座位数超过总座位数，已修正为总座位数" << endl;
    } else if (seatType == SeatType::BUSINESS && targetSeat > totalBusiness) {
        targetSeat = totalBusiness;
        cerr << "警告：商务舱剩余座位数超过总座位数，已修正为总座位数" << endl;
    }
}
void Flight::showFlightInfo() const {
    cout << "==================== 航班详情 ====================" << endl
         << "航班号：\t\t" << flightNum << endl
         << "起降城市：\t\t" << departure << " → " << destination << endl
         << "起飞时间：\t\t" << departTime << endl
         << "座位信息：\t\t经济舱 " << leftEconomy << "/" << totalEconomy
         << "\t商务舱 " << leftBusiness << "/" << totalBusiness << endl
         << "票价信息：\t\t经济舱 " << economyPrice << " 元\t商务舱 " << businessPrice << " 元" << endl
         << "=================================================" << endl;
}
void Flight::showBriefInfo() const {
    cout << "[" << flightNum << "] " << departure << "→" << destination
         << " 剩余：经济舱" << leftEconomy << " 商务舱" << leftBusiness << endl;
}
string Flight::getFlightNum() const { return flightNum; }
string Flight::getDeparture() const { return departure; }
string Flight::getDestination() const { return destination; }
string Flight::getDepartTime() const { return departTime; }
int Flight::getLeftEconomy() const { return leftEconomy; }
int Flight::getLeftBusiness() const { return leftBusiness; }